const UPDATE_PERIOD = 1500;

function updateText() {
  sendMsg("GetText","receiveText");
}

function sendText() {
  var text = getTextToSend();
  sendMsg("ReceiveText","_null",{text:text});
}

function getTextToSend() {
  return $("textToSend").value;
}

function setTextToSend(str) {
  $("textToSend").value = unescape(str).replace(/\+/g,' ');
}

function setReceivedText(str) {
  $("textReceived").value = unescape(str).replace(/\+/g,' ');
}

function getReceivedText() {
  return $("textReceived").value;
}

function addReceivedText(str) {
  var s = getReceivedText();
  if (!s) s = "";
  s += "\n[" + now() + "]\n";
  s += str;
  s += "\n";
  setReceivedText(s);
}

function receiveText(res) {
  if (!res || res == "") return;
  addReceivedText(res);
}

function onLoad() {
  setInterval("updateText()",UPDATE_PERIOD);
  setReceivedText("");
  setTextToSend("");
}
